<template>
  <div class="main">
    <div class="form_content">
      <NScrollbar>
        <NSpin :show="spinShow">
          <div class="content">
            <VDisOrEnd v-if="RecordType.InStorageRouteName" :id="dispatchInfo.workflowInfoVo?.fromId"
              :assigneeFlag="dispatchInfo.workflowInfoVo?.assigneeFlag" typeName="人员入库申请单"></VDisOrEnd>
            <div class="topTitle" v-else>
              人员入库详情
            </div>
            <div class="basin_info">
              <div style="display: flex; align-items: center">
                <div class="basin_five_left">
                  <div class="box">
                    <span>申请人部门：</span>
                    <NEllipsis style="max-width: 100%" placement="left">
                      {{ dispatchInfo.deptName }}
                    </NEllipsis>
                  </div>
                  <div class="box">
                    <span>入库时间：</span>
                    <span>{{ dispatchInfo.inTime }}</span>
                  </div>
                  <div class="box">
                    <span>入库原因：</span>
                    <NEllipsis :line-clamp="1" style="max-width: 400px;">
                      {{ dispatchInfo.reasons }}
                      <template #tooltip>
                        <div style="max-width: 400px;">
                          {{ dispatchInfo.reasons }}
                        </div>
                      </template>
                    </NEllipsis>
                  </div>
                </div>
                <div class="basin_five_left">
                  <div class="box">
                    <span>申请人：</span>
                    <span>{{ dispatchInfo.userName }}</span>
                  </div>
                  <div class="box">
                    <span>出库时间：</span>
                    <span>{{ dispatchInfo.outTime }}</span>
                  </div>
                  <div class="box" style="visibility: hidden;">
                    <span> 11 </span>
                    <span> 11</span>
                  </div>
                </div>

              </div>
              <div style="display: flex; align-items: center;margin-top: 20px;" :key="i.id"
                v-for="i in dispatchInfo.passInfoList">
                <div class="basin-left">
                  <div class="box1" style="width: 300px">
                    <span>姓名：</span>
                    <span>{{ i.name }}</span>
                  </div>
                  <div class="box1" style="width: 300px">
                    <span>车牌号：</span>
                    <span>{{ i.licensePlate }}</span>
                  </div>
                </div>
                <div class="basin-left">
                  <div class="box1" style="width: 350px">
                    <span>手机号：</span>
                    <span>{{ i.phone }}</span>
                  </div>
                  <div class="box1" style="width: 350px">
                    <span>停放位置：</span>
                    <!-- <span>{{ i.address }}</span> -->
                    <NEllipsis :line-clamp="1" style="max-width: 300px;">
                      {{ i.address }}

                      <template #tooltip>
                        <div style="max-width: 400px;">
                          {{ i.address }}
                        </div>
                      </template>
                    </NEllipsis>
                  </div>
                </div>
                <div class="basin-left">
                  <div class="box1" style="width: 350px">
                    <span>身份证：</span>
                    <NEllipsis :line-clamp="1" style="max-width: 300px;">
                      {{ i.idCard }}

                      <template #tooltip>
                        <div style="max-width: 400px;">
                          {{ i.idCard }}
                        </div>
                      </template>
                    </NEllipsis>
                  </div>
                  <div class="box1" style="width: 350px">
                    <span style="width: 180px">是否为特种设备类：</span>
                    <span>{{ i.specialTypeFlag === null ? null : i.specialTypeFlag == '1' ? '是' : '否' }}</span>
                  </div>
                </div>
                <div class="basin-left">
                  <div class="box1">
                    <span>单位：</span>
                    <!-- <span>{{ i.workUnit }}</span> -->
                    <NEllipsis :line-clamp="1" style="max-width: 400px;">
                      {{ i.workUnit }}

                      <template #tooltip>
                        <div style="max-width: 400px;">
                          {{ i.workUnit }}
                        </div>
                      </template>
                    </NEllipsis>
                  </div>
                  <div class="box1" style="width: 405px">
                    <span style="width: 400px">特种设备证持有情况：</span>
                    <NEllipsis :line-clamp="1" style="max-width: 300px;">
                      {{ i.specialDocuments }}

                      <template #tooltip>
                        <div style="max-width: 400px;">
                          {{ i.specialDocuments }}
                        </div>
                      </template>
                    </NEllipsis>
                  </div>
                </div>
              </div>
            </div>
            <div class="topTitle">审批信息</div>
            <div class="approve">
              <div class="box">
                <span>审批状态</span>
                <span style="font-size: 20px;">{{ dispatchInfo.workflowInfoVo?.status }}</span>
              </div>
              <div class="box">
                <span>审批流程</span>
                <div style="color: #5fb17f;font-size: 20px;font-weight: 500;">
                  <div style="display: inline;" v-for="(item, index) in dispatchInfo.workflowInfoVo?.workflowList"
                    :key="index">
                    <span :style="{ textDecoration: item.value ? 'underline' : 'none' }">
                      {{ item.key }}</span>
                    <span v-if="index != dispatchInfo.workflowInfoVo?.workflowList.length - 1">→</span>
                  </div>
                </div>
              </div>
            </div>
            <div class="topTitle">审批记录</div>
            <div class="table">
              <NDataTable :bordered="false" :columns="columns" :data="tableData" :pagination="false" striped
                :rowKey="rowKey" />
            </div>
          </div>
        </NSpin>
      </NScrollbar>
    </div>
  </div>
  <FixedAction>
    <NSpace justify="start">
      <NButton style="width: 78px; color: #5fb17f" ghost @click="goBack">

        <template #icon>
          <img :src="VBackImg" style="width: 25px; height: 25px" />
        </template>
        返回
      </NButton>
    </NSpace>
  </FixedAction>
</template>

<script setup lang="ts">
import {
  NSpace,
  NButton,
  NScrollbar,
  NDataTable,
  useMessage,
  NSpin,
  NImage,
  NEllipsis
} from 'naive-ui'
import type { DataTableColumns } from 'naive-ui'
import router from '@/router'
import { useRoute } from 'vue-router'
import { ref, watch } from 'vue'
import { useTagStore } from '@/stores/layout'
import FixedAction from '@/components/FixedAction.vue'
import { sendRequest } from '@/utils/api'
import type { HttpResponse } from '@/utils/http'
import type { DisModel } from '@/api/receiveOrDispatch'
import VDisOrEnd from '@/views/OA/Common/DisOrEnd.vue'
import VBackImg from '@/assets/images/back.png'
import { RecordType } from '@/router/utils'

const tags = useTagStore().tags
const route = useRoute()
const message = useMessage()

const columns: DataTableColumns = [
  {
    title: '类型',
    key: 'type',
    width: 50
  },
  {
    title: '人员',
    key: 'userName',
    width: 50
  },
  {
    title: '时间',
    key: 'time',
    width: 100
  },
  {
    title: '结果',
    key: 'result',
    width: 50
  },
  {
    title: '备注',
    key: 'remark',
    width: 150
  }
]

const tableData = ref([])
const rowKey: any = (row: any) => row.id || ''

// 返回
const goBack = () => {
  const index = tags.findIndex((item: any) => item.path === router.currentRoute.value.fullPath)

  tags.splice(index, 1)
  if (tags.length == 0) {
    router.push({ path: '/OA/Workbench/UserDesktop' })
  } else history.back()
}
// 获取详情
const spinShow = ref(false)
const dispatchInfo = ref<any>({})
const getInfo = async () => {
  spinShow.value = true
  const [error, res] = await sendRequest<HttpResponse<DisModel>>({
    module: 'inStorage',
    api: 'inoutInfo',
    uri: {
      id: route.query.id as never
    }
  })
  if (error) return message.error(error.message)
  if (res.code !== 0) return message.error(res.msg)
  dispatchInfo.value = res.data
  tableData.value = dispatchInfo.value.workflowInfoVo?.approvalRecordsList || []
  spinShow.value = false
}
watch(
  () => route,
async  () => {
    if (route.path == '/OA/PersonnelInStorage/InOutDetail' && route.query.id) await getInfo()
  },
  { deep: true, immediate: true }
)
</script>

<style scoped lang="scss">
@mixin CommonFont {
  font-size: 18px;
  font-family: PingFangSC, PingFang SC;
  font-weight: 400;
  color: #333333;
}

.main {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;

  .form_content {
    width: 100%;
    height: 100%;
    padding: 20px 20px 0;

    .topTitle {
      font-size: 22px;
      font-family: PingFangSC, PingFang SC;
      font-weight: 500;
      color: #5fb17f;
      margin-bottom: 10px;
    }

    .content {
      display: flex;
      flex-direction: column;
      width: 100%;
      height: 100%;
      padding: 18px 33px 120px;
      overflow-y: scroll;
      background-color: #ebeceb;
      @include CommonFont;

      .basin_info {
        display: flex;
        flex-direction: column;
        width: 100%;
        height: auto;
        border-bottom: 1px dashed #bc9e70;
        margin-bottom: 20px;

        .basin_five_left {
          flex: 0 0 50%;
        }

        .box1 {
          display: flex;
          justify-content: flex-start;
          width: 200px;
          margin-bottom: 20px;

          span {
            width: 100px;
          }
        }

        .box {
          display: flex;
          align-items: center;
          margin-bottom: 10px;
          font-size: 16px;

          span:first-child {
            display: inline-block;
            width: 140px;
            font-weight: bold;
            color: #333333;
            font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
          }

          span:last-child {
            display: inline-block;
            flex: 1;
            color: #55524f;
            font-family: Helvetica Neue, Helvetica, Arial, sans-serif;

          }
        }

        .basin-left {
          .box1 {
            display: flex;
            align-items: center;
            margin-bottom: 10px;
            font-size: 16px;

            span:first-child {
              display: inline-block;
              width: 120px;
              font-weight: bold;
              color: #333333;
              font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
            }

            span:last-child {
              display: inline-block;
              flex: 1;
              color: #55524f;
              font-family: Helvetica Neue, Helvetica, Arial, sans-serif;

            }
          }
        }

      }

      .approve {
        display: flex;
        width: 100%;
        margin-bottom: 20px;
        border-bottom: 1px dashed #bc9e70;

        .box {
          display: flex;
          flex-direction: column;
          justify-content: center;
          min-width: 50px;
          width: auto;
          height: 90px;
          border-radius: 4px;
          border: 1px solid #d9d9d9;
          padding: 12px;
          margin-right: 10px;
          margin-bottom: 20px;

          span:first-child {
            font-size: 16px;
          }

          span:last-child {
            font-weight: 500;
            color: #5fb17f;
          }
        }
      }

      .table {
        width: 80%;
        background-color: #e1e1e1;
      }
    }
  }
}

.content::-webkit-scrollbar {
  display: none;
}

:deep(.n-spin-container) {
  width: 100%;
  height: 100%;
}

:deep(.n-scrollbar-container) {
  width: 100%;
  height: 100%;
}

:deep(.n-scrollbar-content) {
  width: 100%;
  height: 100%;
}

:deep(.n-spin-content) {
  width: 100%;
  height: 100%;
}

:deep(.n-ellipsis:not(.n-ellipsis--line-clamp)) {
  color: #55524f !important;
  font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
}

:deep(.n-ellipsis.n-ellipsis--line-clamp) {
  color: #55524f;
  font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
}
</style>
